﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DonutMgmtSystemFoundation.Helpers;

namespace DonutMgmtSystemFoundation.App_Start
{
    public class AutorizeRoleAttribute : AuthorizeAttribute
    {
        public string Permission { get; set; }

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var isAuthorized = base.AuthorizeCore(httpContext);
            if (!isAuthorized)
            {
                return false;
            }

            // My method to get permisions
            if (SessionContext.GetUserData().Role.Name == this.Permission)//**** problem line
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}